package com.ruoyi.operator.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.DateUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.operator.mapper.OptShopCategoryMapper;
import com.ruoyi.operator.domain.OptShopCategory;
import com.ruoyi.operator.service.IOptShopCategoryService;
import com.ruoyi.common.core.text.Convert;

/**
 * 商家类目Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-02-08
 */
@Service
public class OptShopCategoryServiceImpl implements IOptShopCategoryService 
{
    @Autowired
    private OptShopCategoryMapper optShopCategoryMapper;

    /**
     * 查询商家类目
     * 
     * @param categoryId 商家类目ID
     * @return 商家类目
     */
    @Override
    public OptShopCategory selectOptShopCategoryById(Long categoryId)
    {
        return optShopCategoryMapper.selectOptShopCategoryById(categoryId);
    }

    /**
     * 查询商家类目列表
     * 
     * @param optShopCategory 商家类目
     * @return 商家类目
     */
    @Override
    public List<OptShopCategory> selectOptShopCategoryList(OptShopCategory optShopCategory)
    {
        return optShopCategoryMapper.selectOptShopCategoryList(optShopCategory);
    }

    /**
     * 新增商家类目
     * 
     * @param optShopCategory 商家类目
     * @return 结果
     */
    @Override
    public int insertOptShopCategory(OptShopCategory optShopCategory)
    {
        SysUser currentUser  = (SysUser) SecurityUtils.getSubject().getPrincipal();
        optShopCategory.setCreateTime(DateUtils.getNowDate());
        String number = RandomStringUtils.randomNumeric(6);
        optShopCategory.setDeptId(String.valueOf(currentUser.getDeptId()));
        optShopCategory.setCategoryNumber(Long.parseLong(currentUser.getDeptId()+number));
        return optShopCategoryMapper.insertOptShopCategory(optShopCategory);
    }

    /**
     * 修改商家类目
     * 
     * @param optShopCategory 商家类目
     * @return 结果
     */
    @Override
    public int updateOptShopCategory(OptShopCategory optShopCategory)
    {
        optShopCategory.setUpdateTime(DateUtils.getNowDate());
        return optShopCategoryMapper.updateOptShopCategory(optShopCategory);
    }

    /**
     * 删除商家类目对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteOptShopCategoryByIds(String ids)
    {
        return optShopCategoryMapper.deleteOptShopCategoryByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除商家类目信息
     * 
     * @param categoryId 商家类目ID
     * @return 结果
     */
    @Override
    public int deleteOptShopCategoryById(Long categoryId)
    {
        return optShopCategoryMapper.deleteOptShopCategoryById(categoryId);
    }

    @Override
    public List<OptShopCategory> selectOptShopCategoryinfo(OptShopCategory optshopcategory) {
        return optShopCategoryMapper.selectOptShopCategoryinfo(optshopcategory);
    }

    @Override
    public int changeStatus(OptShopCategory optShopCategory) {
        return optShopCategoryMapper.changeStatus(optShopCategory);
    }

}
